<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_banners
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Helper for mod_banners
 *
 * @package     Joomla.Site
 * @subpackage  mod_banners
 * @since       1.5
 */

JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_weblinks/models', 'WeblinksModel');
class ModWeblinksFeaturedHelper
{
	public static function getList(&$params)
	{
		
		
		// Get the dbo
		$db = JFactory::getDbo();

		// Get an instance of the generic articles model
		$model = JModelLegacy::getInstance('Weblink', 'WeblinksModel', array('ignore_request' => true));
		
		// Set application parameters in model
		$app = JFactory::getApplication();
		$appParams = $app->getParams();
		
		
		$model->setState('params', $appParams);
		
		// Set the filters based on the module params
		$model->setState('list.start', 0);
		$model->setState('list.limit', (int) $params->get('count', 5));
		$model->setState('filter.published', 1);

		
		
		// Access filter
		$access = !JComponentHelper::getParams('com_weblinks')->get('show_noauth');
		$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
		$model->setState('filter.access', $access);

		// Category filter
		$model->setState('filter.category_id', $params->get('catid', array()));

				
		$nullDate = $db->quote($db->getNullDate());
		$nowDate = $db->quote(JFactory::getDate()->toSQL());
		$query = $db->getQuery(true);
		
		
		$catids = $params->get('catid', array());
		
		
		
		$query->select('c.*')
		->from('#__weblinks c')
		->where('c.state = 1 AND c.checked_out = 0 AND c.featured=1')			
		->where('(c.catid=' . $catids[0] . ')')
		->order('c.featured DESC, c.created DESC');
		
		
		
		$db->setQuery($query, 0, (int) $params->get('count'));
		$rows = (array) $db->loadObjectList();
		
		$app = JFactory::getApplication();
		$menu = $app->getMenu();
						
		return $rows;
		
	}
}
